#include <iostream>
#include <zlib.h>

using   namespace   std;

#define MaxBufferSize 999999

void Test1();

int main(int argc, char *argv[])
{

    Test1();
    cout << "main endl" << endl;
    return 0;
}

//c++ zlib
void Test1()
{
    FILE* File_src;
    FILE* File_compress;
    FILE* File_uncompress;

    unsigned long len_src;
    unsigned long len_compress;
    unsigned long len_uncompress;

    unsigned char *buffer_src  = new unsigned char[MaxBufferSize];
    unsigned char *buffer_compress  = new unsigned char[MaxBufferSize];
    unsigned char *buffer_uncompress = new unsigned char[MaxBufferSize];

    File_src = fopen("src.txt","r");
    File_compress = fopen("compress.txt","w");
    File_uncompress = fopen("uncompress.txt","w");

    //compress
    len_src = fread(buffer_src,sizeof(char),MaxBufferSize-1,File_src);
    compress(buffer_compress,&len_compress,buffer_src,len_src);
//    compress((Bytef *)buffer_compress,&len_compress,(Bytef *)buffer_src,len_src);
    fwrite(buffer_compress,sizeof(char),len_compress,File_compress);
    cout << "normal zlib:" << endl;
    cout << "src:\n" << buffer_src << ",length:" << len_src << endl << endl;
    cout << "compress:\n" << buffer_compress << ",length:" << len_compress << endl << endl;

    //uncompress
    uncompress(buffer_uncompress,&len_uncompress,buffer_compress,len_compress);
//    uncompress((Bytef *)buffer_uncompress,&len_uncompress,(Bytef *)buffer_compress,len_compress);
    fwrite(buffer_uncompress,sizeof(char),len_uncompress,File_uncompress);
    cout << "uncompress:\n" << buffer_uncompress << ",length:" << len_uncompress << endl << endl;

    fclose(File_src);
    fclose(File_compress);
    fclose(File_uncompress);
}

